package com.ruoyi.system.service;

import com.ruoyi.common.core.domain.entity.SysArea;
import com.ruoyi.common.core.redis.RedisCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.Collection;
import java.util.List;

/**
 * ClassName: SysAreaCacheInitService
 * Function:  TODO
 * Date:      2022/5/25 10:20
 * author     yu
 * version    V1.0
 */
@Service
public class SysAreaCacheInitService {

    private static final Logger logger = LoggerFactory.getLogger(SysAreaCacheInitService.class);

    @Autowired
    RedisCache redisCache;

    @Autowired
    private ISysAreaService areaService;

//    @PostConstruct
    public void init() {
        logger.info("全国行政区划存入缓存");
        SysArea areaParam = new SysArea();
        areaParam.setStatus("0");
        List<SysArea> list = areaService.selectAreaList(areaParam);
//        redisCache.setCacheObject(SysArea.CACHE_KEY_SYS_AREA, list);

//        Collection<String> keys = redisCache.keys(SysArea.CACHE_KEY_SYS_AREA_PROVINCE_CITY + "*");
//        redisCache.deleteObject(keys);


        list.stream().forEach(e -> {
            redisCache.setCacheObject(SysArea.CACHE_KEY_SYS_AREA_ID + "_" + e.getDeptId(), e);
//            if ("1".equals(e.getRiskflag()) || "2".equals(e.getRiskflag()) || "4".equals(e.getRiskflag()) || "9".equals(e.getRiskflag())) {
//                redisCache.setCacheObject(SysArea.CACHE_KEY_SYS_AREA_PROVINCE_CITY + "_" + e.getProvinceName() + e.getDeptName(), e);
//            }
        });

    }
}
